/* global Hi  window*/

exports.isTeacher = function() {
    return Hi.user.position && Hi.user.position.indexOf("Teacher") >= 0
}

exports.getQueryParameter = function(name, url) {
    if (!url) url = window.location.href
    console.log(url, "url")
    name = name.replace(/[[\]]/g, "\\$&")
    let regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url)
    if (!results) return null
    if (!results[2]) return ""
    return decodeURIComponent(results[2].replace(/\+/g, " "))
}


exports.checkAbility = function(arr, val) {
    return arr.some(function(arrVal) {
        return val === arrVal
    })
}


exports.generateUUID = function() {
    let d = new Date().getTime()
    let uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
        let r = (d + Math.random() * 16) % 16 | 0
        d = Math.floor(d / 16)
        return (c === "x" ? r : (r & 0x3 | 0x8)).toString(16)
    })
    return uuid
}
